package com.timothy.android.answer;

import android.graphics.Color;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.util.Log;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TableLayout;
import android.widget.TextView;

import com.timothy.android.BaseProcessActivity;
import com.timothy.android.R;
import com.timothy.question.BaseQuestion;
import com.timothy.statistics.FreeFormStatistics;
import com.timothy.statistics.StatisticsBuilder;

public class FreeFormAnswerActivity extends BaseProcessActivity {
	private static final String LOG_TAG = "FreeFormAnswerActivity";
	
	private TableLayout tableLayout1;
	private TextView yourAnswerDesc,collectAnswerDesc;
	private EditText yourAnswer,collectAnswer;
	
	private ImageView imgAnswer;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		// TODO Auto-generated method stub
		super.onCreate(savedInstanceState);
		setContentView(R.layout.freeform_answer);
		
		Bundle bundle = this.getIntent().getExtras();
		String message = bundle.getString("message");
		Log.i(LOG_TAG, "message:"+message);
		
		FreeFormStatistics statistics = StatisticsBuilder.parseFreeFormStatistics(message);
		BaseQuestion bq = statistics.getQuestion();
		
		//set title
		this.setTitle("(SlideIndex:"+bq.getSlideIndex()+")");
		
		//set layout
		//layoutSlider = (LinearLayout) this.findViewById(R.id.layoutSlider);
		 
		//set tableLayout
		tableLayout1 = (TableLayout) this.findViewById(R.id.tableLayout1);
		tableLayout1.setBackgroundColor(Color.parseColor("#bd63ed"));
		
		//set total
		yourAnswerDesc = (TextView) this.findViewById(R.id.yourAnswerDesc);
		yourAnswerDesc.setTextSize(15);
 
		yourAnswer = (EditText) this.findViewById(R.id.yourAnswer);
		yourAnswer.setTextSize(30);
		yourAnswer.setText("");
		        
		//set average
        collectAnswerDesc = (TextView) this.findViewById(R.id.collectAnswerDesc);
        collectAnswerDesc.setTextSize(15);
		
        collectAnswer = (EditText) this.findViewById(R.id.collectAnswer);
        collectAnswer.setTextSize(30);
        collectAnswer.setText(String.valueOf(statistics.getAnswer()));
        
        Drawable collectDraw = this.getResources().getDrawable(R.drawable.collect);
        Drawable incollectDraw = this.getResources().getDrawable(R.drawable.incollect);
        
        imgAnswer = (ImageView) this.findViewById(R.id.imgAnswer);
        boolean flag = true;
        if(flag){
        	imgAnswer.setImageDrawable(collectDraw);
        }else{
        	imgAnswer.setImageDrawable(incollectDraw);
        }
        
	}

	@Override
	protected void onDestroy() {
		// TODO Auto-generated method stub
		super.onDestroy();
	}

	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		super.onResume();
	}

	@Override
	protected void onPause() {
		// TODO Auto-generated method stub
		super.onPause();
	}

}
